package com.perfect.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.perfect.feign.StockFeignService;
import com.perfect.utils.ExceptionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("oms-order")
@Slf4j
public class OrderController {

    @Autowired
    private StockFeignService stockFeignService;

    @GetMapping("/genneration/comfirm/order")
    public String gennerationComfirmOrder(String id) {

        String result = stockFeignService.reduct(id);
        log.info("扣减库存:" + result);
        return "订单生成成功" + id;
    }

    /**
     * feign 原生注解使用示例
     */
//    @GetMapping("/contract")
//    public void contract(){
//
//        stockFeignService.contractTest();
//        return ;
//    }

    @SentinelResource(value = "/get",
            blockHandler = "blockHandler",blockHandlerClass = ExceptionUtils.class,
            fallback = "fallback", fallbackClass = ExceptionUtils.class)
    @GetMapping("/get")
    public String get(@RequestParam(required = false) String id){

        return "查询订单"+id;
    }

    @SentinelResource(value = "/add",
            blockHandler = "blockHandler",blockHandlerClass = ExceptionUtils.class,
            fallback = "fallback", fallbackClass = ExceptionUtils.class)
    @PostMapping("/add")
    public String add(@RequestParam(required = false) String id){

        return "创建订单"+id;
    }

}
